module.exports = (function() {
    var express = require('express');
    var router = express.Router();
    var path = require('path');
    var uid = require('uid');
    router.get('/', function(req, res) {
        res.clearCookie('uid');
        res.sendFile(path.join(__dirname, './../views/login.html'));
    });
    var redis = require('redis');
    router.post('/', function(req, res) {
        var sha1 = require('sha1');
        var body = req.body;
        var hash = sha1(body.password);

        res.cookie('username', body.username, {
            expires: new Date(Date.now() + 3600 * 1000 * 24 * 10)
        });
        var id = uid(10);
        res.cookie('uid', id, {
            expires: new Date(Date.now() + 3600 * 1000 * 24 * 10)
        });
        redisClient = redis.createClient();
        var nameSpace = "metroProject";
        redisClient.set(nameSpace + ":" + id, id);
        setTimeout((function() {
            redisClient.quit();
        })(redisClient), 200);
        //post this hash to api
        res.redirect('/');


        // console.log("Cookies: ", req.cookies);

    });
    return router;
})();
